package top.goldenyear.porpoise.common.core.model;

import java.io.Serializable;
import lombok.*;

/**
 * 下拉 checkbox radio的数据源Bean
 *
 * @author airhead
 */
@Data
@Builder
public class PlainOption implements Serializable, Option {
  private String name;
  private Object value;
  @Getter private Boolean selected;

  public PlainOption() {}

  public PlainOption(String name) {
    this.name = name;
    this.value = name;
  }

  public PlainOption(String name, Object value) {
    this.name = name;
    this.value = value;
  }

  public PlainOption(String name, Object value, Boolean selected) {
    this.name = name;
    this.value = value;
    this.selected = selected;
  }

  @Override
  public Object getValue() {
    return value;
  }

  @Override
  public String getName() {
    return name;
  }

  @SuppressWarnings("unchecked")
  public <T> T valueAs() {
    return (T) value;
  }
}
